<?php

class DatabasePDO{
    
    

    private static $_mHandler;
    
    private function _construct(){
        
    }
    
    
    private static function instance(){
        if(!isset(self::$_mHandler)){
            self::$_mHandler = new PDO(PDO_DSN, DB_USERNAME, DB_PASSWORD,
                        array(PDO::ATTR_PERSISTENT => DB_PERSISTENCY));
        
        }
        return self::$_mHandler;
    }
    
    public static function Execute($sqlQuery, $param = null){
        $database_handler = self::instance();
        $statement_handler = $database_handler->prepare($sqlQuery);
        
        $statement_handler->execute($param);
    }
    
    
    public static function GetAll($sqlQuery, $params = null, $fetchStyle = PDO::FETCH_ASSOC){
        
        $database_handler = self::instance();
        $statement_handler = $database_handler->prepare($sqlQuery);
        $statement_handler->execute($params);
        
        return $statement_handler->fetchAll($fetchStyle);
    }
    
    public static function GetRow($sqlQuery, $params = null, $fetchStyle = PDO::FETCH_ASSOC){
        $database_handler = self::instance();
        $statement_handler = $database_handler->prepare($sqlQuery);
        $statement_handler->execute($params);
        
        return $statement_handler->fetch($fetchStyle);
    }
    
    public static function GetOne($sqlQuery, $params = null){
        $result = null;
        $database_handler = self::instance();
        $statement_handler = $database_handler->prepare($sqlQuery);
        $statement_handler->execute($params);
        
        $result =  $statement_handler->fetch(PDO::FETCH_NUM);
        return $result[0];
    }
}
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
?>
